/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package herramientas;

import java.io.*;

/**
 *
 * @author javier
 */
public class carnet {

	public String carnet(String ci) {
		try {

	    String ldap = "ldapsearch -xLLL -h ldap.usb.ve -b ou=People,dc=usb,dc=ve \"(personalId="+ci+")\" ";
			//String ldap = "ssh garon.ldc.usb.ve 'ldapsearch -xLLL -h ldap.usb.ve -b ou=People,dc=usb,dc=ve \"(personalId=" + ci + ")\" '";
			String[] buscar = {
				"/bin/sh",
				"-c",
				"  " + ldap + " | grep uid: | awk '{print $2}';"
				+ " " + ldap + "  | grep career: | awk -F ': ' '{print $2}';"
				+ "" + ldap + "| grep givenName: |awk -F ': '  '{print $2}';"
				+ "" + ldap + "| grep sn: | awk -F ': '  '{print $2}';",};


			Process p = Runtime.getRuntime().exec(buscar);
			BufferedReader in = new BufferedReader(
				new InputStreamReader(p.getInputStream()));
			String line = null;
			String car = "";
			int i = 0;
			while ((line = in.readLine()) != null) {
				car = car + "," + line;
				i++;
			}
			return car;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public String profesor(String ci) {
		try {

			String ldap = "ldapsearch -xLLL -h ldap.usb.ve -b ou=People,dc=usb,dc=ve \"(personalId=" + ci + ")\" ";
			//String ldap = "ssh garon.ldc.usb.ve 'ldapsearch -xLLL -h ldap.usb.ve -b ou=People,dc=usb,dc=ve \"(personalId=" + ci + ")\" '";

			String[] buscar = {
				"/bin/sh",
				"-c",
				"  " + ldap + " | grep givenName: | awk '{print $2}';"
				+ "" + ldap + "  | grep sn: | awk '{print $2}';"
				+ "" + ldap + "  | grep department: | awk -F ': ' '{print $2}';"
				+ "" + ldap + " | grep mail: | awk -F ': ' '{print $2}';"
				+ "" + ldap + " | grep career: | awk -F ': ' '{print $2}'",};


			Process p = Runtime.getRuntime().exec(buscar);
			BufferedReader in = new BufferedReader(
				new InputStreamReader(p.getInputStream()));
			String line = null;
			String car = "";
			int i = 0;
			while ((line = in.readLine()) != null) {
				car = car + "," + line;
				i++;
			}
			return car;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
}
